// LedTest.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "gtest/gtest.h"
#include <iostream>
#include <nled.h>
using namespace std;

#define SCAN_GREEN_LED          1  
#define SCAN_RED_LED            0  
#define DECODE_GREEN_LED        3  
#define DECODE_RED_LED          2  

class LED
{
private:
	UINT16	KBD_BLT_ON;
	UINT16 KBD_BLT_OFF;
	void SetLED (int led, int val) 
	{
		static NLED_SETTINGS_INFO ledsetting;  
		memset(&ledsetting,0,sizeof(ledsetting));
		ledsetting.LedNum=led;  
		ledsetting.OffOnBlink=val;
		NLedSetDevice( NLED_SETTINGS_INFO_ID , &ledsetting);
		return;
	}
	int GetLED (int led) 
	{
		int val;
		static NLED_SETTINGS_INFO ledsetting;  
		memset(&ledsetting,0,sizeof(ledsetting));
		ledsetting.LedNum=led;  
		NLedGetDeviceInfo( NLED_SETTINGS_INFO_ID , &ledsetting);
		val=ledsetting.OffOnBlink;
		return val;
	}

	int GetNumLEDs ( void ) 
	{
		static NLED_COUNT_INFO ledcount;
		NLedGetDeviceInfo( NLED_COUNT_INFO_ID , &ledcount);
		return (int)ledcount.cLeds;
	}

public:
	int initial()
	{
		KBD_BLT_ON = 0x1;
		KBD_BLT_OFF = 0x0;
		cout<<"reset the LEDs"<<endl;
		SetLED(DECODE_GREEN_LED,false);
		SetLED( DECODE_RED_LED,false );
		SetLED( SCAN_GREEN_LED,false );
		SetLED( SCAN_RED_LED,false );
		cout<<"done!";
		cout<<endl<<"------------------------------------------------------"<<endl;
		return 1;
	}
	int twinkle(int ledType)
	{
		cout<<"start..."<<endl;
		for(int i=0;i<3;++i)
		{	
			cout<<i+1<<"...";
			SetLED( ledType,true );
			Sleep(0.5*1000);
			SetLED(ledType,false);
			Sleep(0.5*1000);
		}
		cout<<endl<<"------------------------------------------------------"<<endl;
		return 1;
	}
};


int _tmain(int argc, _TCHAR* argv[])
{
	testing::InitGoogleTest(&argc, argv);
	return RUN_ALL_TESTS();
}

class LedTest : public testing::Test
{
protected:
	static void SetUpTestCase()
	{
		led = new LED();
		cout<<"start"<<endl;
	}
	static void TearDownTestCase()
	{
		delete led;
	}
	static LED* led;
};
LED* LedTest::led = NULL;

TEST_F(LedTest,INITIAL)
{
	EXPECT_EQ(1,led->initial());
}

TEST_F(LedTest,GREENLED)
{
	EXPECT_EQ(1,led->twinkle(SCAN_GREEN_LED));
}

TEST_F(LedTest,REDLED)
{
	EXPECT_EQ(1,led->twinkle(SCAN_RED_LED));
}